package com.biyabi.controller;

import com.biyabi.entity.Supplier;
import com.biyabi.pojo.Result;
import com.biyabi.pojo.SuppliersData;
import com.biyabi.service.SupplierService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/back/supplier")
public class SupplierController {
    @Resource
    private SupplierService SupplierService;
    @RequestMapping("/findAll")
    public SuppliersData findAll(Integer page, Integer rows,String columnName,String columnValue){
        return SupplierService.findAll(page,rows,columnName,columnValue);
    }
    @RequestMapping("/findAllSupplier")
    public List<Supplier> findAllSupplier(){
        return SupplierService.findAllSupplier();
    }
    @RequestMapping("/add")
    public Result add(Supplier Supplier, MultipartFile addLogoFile, HttpServletRequest request){
        Result result = new Result();
        try{
            SupplierService.add(Supplier,addLogoFile,request);
            result.setStatus(true);
            result.setMessage("添加供货商成功！");
        }catch(Exception e){
            result.setStatus(false);
            result.setMessage("添加供货商失败！");
        }
        return result;
    }
    @RequestMapping("/update")
    public Result update(Supplier Supplier, MultipartFile updateLogoFile, HttpServletRequest request){
        Result result = new Result();
        try{
            SupplierService.update(Supplier,updateLogoFile,request);
            result.setStatus(true);
            result.setMessage("更新供货商成功！");
        }catch(Exception e){
            result.setStatus(false);
            result.setMessage("更新供货商失败！");
        }
        return result;
    }

    @RequestMapping("/findOne")
    public Supplier findOne(String id){
        return SupplierService.findOne(id);
    }

}
